package com.aiyige.page.interest.searchinterest.model;

import android.text.TextUtils;

public class SearchData {
    public static final int TYPE_NORMAL = 1;
    public static final int TYPE_ADD = 2;
    String title;
    String id;
    String sourceId;
    int type;
    String description;

    public SearchData() {
    }

    private SearchData(Builder builder) {
        setTitle(builder.title);
        setId(builder.id);
        setSourceId(builder.sourceId);
        setType(builder.type);
        setDescription(builder.description);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getSourceId() {
        return sourceId;
    }

    public void setSourceId(String sourceId) {
        this.sourceId = sourceId;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public static final class Builder {
        private String title;
        private String id;
        private String sourceId;
        private int type;
        private String description;

        private Builder() {
            id = "";
            sourceId = "";
            title = "";
            type = TYPE_NORMAL;
            description = "";
        }

        public Builder title(String val) {
            title = val;
            return this;
        }

        public Builder id(String val) {
            id = val;
            return this;
        }

        public Builder sourceId(String val) {
            sourceId = val;
            return this;
        }

        public Builder type(int val) {
            type = val;
            return this;
        }

        public Builder description(String val) {
            description = val;
            return this;
        }

        public SearchData build() {
            return new SearchData(this);
        }
    }

    public static SearchData parse(SearchResp searchResp) {
        return SearchData.newBuilder()
                .id(searchResp.id)
                .description(searchResp.description)
                .title(searchResp.name)
                .type(TextUtils.isEmpty(searchResp.id) ? SearchData.TYPE_ADD : SearchData.TYPE_NORMAL)
                .build();
    }
}
